﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace RouterControl.WhsAddIn.SettingsControls
{
	public partial class SearchingForRouter : SettingsControlBase
	{
		public SearchingForRouter(RouterControlSettingsTab2 tab)
			: base(tab)
		{
			InitializeComponent();

			this.lineBox.Header.Text = Properties.Resources.txtSettingsSelectedRouter;
		}

		private void SearchingForRouter_Load(object sender, EventArgs e)
		{
			this.bgWorker.RunWorkerAsync();
		}

		private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
		{
            try
            {
                _singletonService.Channel.EnsureFirstSearchForDevices(true);

            }
            catch (Exception x)
            {
                _log.Error("Failed to wait for device search", x);
            }
        }

		private void bgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
		{
            try
            {
                _tab.SetState(RouterControlSettingsTab2.SettingsState.Ready);

            }
            catch (Exception x)
            {
                _log.Error("Failed to handle devices-found status", x);

                throw;
            }
        }


	}
}
